package com.ddf.entity;

import org.hibernate.annotations.GenericGenerator;

import javax.persistence.*;

/**
 * @author DDf on 2018/9/22
 */
@Entity
@Table(name = "ID_CARD")
public class IdCard {
    private Integer id;
    private String name;
    private String cardNo;
    private String address;
    private User user;

    public IdCard() {
    }

    public IdCard(String name, String cardNo, String address, User user) {
        this.name = name;
        this.cardNo = cardNo;
        this.address = address;
        this.user = user;
    }

    @Id
    @GeneratedValue
    @GenericGenerator(name="increment", strategy = "increment")
    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    @Column(name = "NAME")
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Column(name = "CARD_NO")
    public String getCardNo() {
        return cardNo;
    }

    public void setCardNo(String cardNo) {
        this.cardNo = cardNo;
    }

    @Column(name = "ADDRESS")
    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    /**
     * @see User#getIdCard()
     * @return
     */
    @JoinColumn(name = "USER_ID", unique = true)
    @OneToOne(targetEntity = User.class, fetch = FetchType.EAGER)
    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    @Override
    public String toString() {
        return "IdCard{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", cardNo='" + cardNo + '\'' +
                ", address='" + address + '\'' +
                '}';
    }
}
